package com.one.controller;

import com.one.bean.Activity;
import com.one.bean.Category;
import com.one.bean.Product;
import com.one.bean.ProductView;
import com.one.service.HomePageService;
import com.one.util.RequestReturn;
import com.one.util.RequestReturnFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: tzy
 * @create: 2022/1/14
 * @FileName: HomePageController
 * @Description: 首页展示操作入口
 */
@Slf4j
@RestController
@RequestMapping("/homePage")
public class HomePageController {
    @Autowired
    private HomePageService homePageService;

    /**
     * @author: tzy
     * @date: 2022/1/14
     * @return:
     * @Description: 查询指定分类的热销商品
     */
    @GetMapping("/hotProducts")
    public RequestReturn<List<Product>> queryHotProducts(@RequestParam("categoryFirst") Integer categoryFirst){
        //调用service接口,查询指定分类的热销商品
        if (categoryFirst != null){
            return RequestReturnFactory.success(homePageService.findHotProducts(categoryFirst));
        }else {
            List list = new ArrayList<>();
            list.add("未指定商品分类，查询失败！！");
            return RequestReturnFactory.fail(list);
        }
    }

    /**
     * @author: tzy
     * @date: 2022/1/14
     * @return:
     * @Description: 根据商品一级分类，查询一二级分类的名称
     */
    @GetMapping("/categories")
    public RequestReturn<List<Category>> queryCategories(@RequestParam("categoryFirst") Integer categoryFirst){
        //调用service接口,查询指定商品一级分类，查询一二级分类的名称
        if (categoryFirst != null){
            return RequestReturnFactory.success(homePageService.findCategories(categoryFirst));
        }else {
            List list = new ArrayList<>();
            list.add("未指定商品分类，查询失败！！");
            return RequestReturnFactory.fail(list);
        }
    }

    /**
     * @author: tzy
     * @date: 2022/1/17
     * @return:
     * @Description: 查询商品对应分类的新品
     */
    @GetMapping("/products")
    public RequestReturn<List<Product>> queryNewProducts(@RequestParam("categoryFirst") Integer categoryFirst){
        //调用service接口,查询指定分类的新品商品
        if (categoryFirst != null){
            return RequestReturnFactory.success(homePageService.findNewProducts(categoryFirst));
        }else {
            List list = new ArrayList<>();
            list.add("未指定商品分类，查询失败！！");
            return RequestReturnFactory.fail(list);
        }
    }




    /**
     * @author: tzy
     * @date: 2022/1/17
     * @return:
     * @Description: 首页限时，秒杀，热销跳转
     */
    @GetMapping("/moduleToJump")
    public RequestReturn<List<Activity>> queryActivities(){
        //调用service接口,查询首页限时，秒杀，热销等活动的跳转
        return  RequestReturnFactory.success(homePageService.findActivities());
    }
}
